<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">

<head th:include="include :: header">
</head>
<link rel="stylesheet" th:href="@{/css/yw.css}">

<body class="hold-transition skin-blue sidebar-mini">
    <!--查看回款模态框-->
    <div class="modal fade" id="modal-select-money">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">查看收款信息</h4>
                </div>
                <div class="modal-body">
                    <form id="moneyForm-select" class="form-horizontal" role="form">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">款项</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="rmiName" autocomplete="off" placeholder=""
                                    readonly>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">款项比例</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="rmiExpectScale" autocomplete="off"
                                    placeholder="" readonly>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">应收金额</label>
                            <div class="col-sm-8">
                                <input type="number" class="form-control" name="singleRmiExpectMoney" autocomplete="off"
                                    readonly>
                            </div>
                        </div>
                        <div class="form-group" id="ysjeDiv-select">
                            <label class="col-sm-3 control-label">已收金额</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="singleAlreadyMoney" autocomplete="off"
                                    placeholder="" readonly>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">实际已收金额</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="rmiActualMoney" autocomplete="off"
                                    placeholder="" readonly>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">未收金额</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="singleReceivableNotReceivedMoney"
                                    autocomplete="off" placeholder="" readonly>
                            </div>
                        </div>
                        <div class="form-group" id="yswsDiv-select">
                            <label class="col-sm-3 control-label">应收未收</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="yingshouweishou" autocomplete="off"
                                    placeholder="" readonly>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">预计回款时间</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="rmiExpectDate" autocomplete="off"
                                    placeholder="" readonly>
                            </div>
                        </div>
                        <div class="form-group" id="mzjeDiv-select">
                            <label class="col-sm-3 control-label">抹账金额</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="singleRmiDebtsMoney" autocomplete="off"
                                    placeholder="抹账" readonly>
                            </div>
                        </div>
                        <div class="form-group" id="hzjeDiv-select">
                            <label class="col-sm-3 control-label">坏账金额</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="singleRmiBadMoney" autocomplete="off"
                                    placeholder="坏账" readonly>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                </div>
            </div>
        </div>
    </div>

    <!--编辑回款模态框-->
    <div class="modal fade" id="modal-edit-money">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">修改收款信息</h4>
                </div>
                <div class="modal-body">
                    <form id="moneyForm-edit" class="form-horizontal" role="form">
                        <input type="hidden" class="form-control" name="conId" autocomplete="off">
                        <input type="hidden" class="form-control" name="rmiIsAll" autocomplete="off">
                        <input type="hidden" class="form-control" name="rmiMoneyType" autocomplete="off">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">款项</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="rmiName" autocomplete="off" readonly>
                            </div>
                        </div>
                        <!--<div class="form-group">-->
                        <!--<label class="col-sm-3 control-label">款项比例</label>-->
                        <!--<div class="col-sm-8">-->
                        <!--<input type="text" class="form-control" name="rmiExpectScale" autocomplete="off"-->
                        <!--readonly>-->
                        <!--</div>-->
                        <!--</div>-->
                        <div class="form-group">
                            <label class="col-sm-3 control-label">应收金额</label>
                            <div class="col-sm-8">
                                <input type="number" class="form-control" name="singleRmiExpectMoney" autocomplete="off"
                                    readonly>
                            </div>
                        </div>
                        <div class="form-group" id="ysjeDiv-edit">
                            <label class="col-sm-3 control-label">已收金额</label>
                            <div class="col-sm-8">
                                <input type="number " min="0"
                                    onkeyup="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''"
                                    class="form-control" name="singleAlreadyMoney" autocomplete="off" readonly>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">实际已收金额</label>
                            <div class="col-sm-8">
                                <input type="number " min="0"
                                    onkeyup="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''"
                                    class="form-control" name="rmiActualMoney" autocomplete="off">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">未收金额</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="singleReceivableNotReceivedMoney"
                                    autocomplete="off" placeholder="" readonly>
                            </div>
                        </div>
                        <div class="form-group" id="yswsDiv-edit">
                            <label class="col-sm-3 control-label">应收未收</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="yingshouweishou" autocomplete="off"
                                    placeholder="" readonly>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">预计回款时间</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control datepicker" name="rmiExpectDate"
                                    autocomplete="off" readonly>
                            </div>
                        </div>
                        <div class="form-group" id="mzjeDiv-edit">
                            <label class="col-sm-3 control-label">抹账金额</label>
                            <div class="col-sm-8">
                                <input type="number " min="0"
                                    onkeyup="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''"
                                    class="form-control" name="singleRmiDebtsMoney" autocomplete="off">
                            </div>
                        </div>
                        <div class="form-group" id="hzjeDiv-edit">
                            <label class="col-sm-3 control-label">坏账金额</label>
                            <div class="col-sm-8">
                                <input type="number " min="0"
                                    onkeyup="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''"
                                    class="form-control" name="singleRmiBadMoney" autocomplete="off">
                            </div>
                        </div>

                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-success" id="btn-save1" data-dismiss="modal"
                        onclick="saveUpdateMoney1()" shiro:hasPermission="pay:infor:edit">
                        <span class="Bold">保存</span>
                    </button>

                </div>
            </div>
        </div>
    </div>

    <!--上传模态框-->
    <div class="modal fade" data-backdrop="static" data-keyboard="false" id="modal-import">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">上传附件</h4>
                </div>
                <div class="modal-body">
                    <form id="importForm">
                        <input type="hidden" id="invId" name="invId">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">选择文件并上传</label>
                            <div class="col-sm-8">
                                <input type="hidden" class="form-control" name="" autocomplete="off">
                            </div>
                            <input id="import-file" class="btn" type="file" name="file">
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">文件备注</label>
                            <div class="col-sm-8">
                                <textarea class="form-control text-left" rows="2" name="remark">
                        </textarea>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button id="btn-import" type="button" class="btn btn-success" style="margin-top: 20px">
                        <span class="Bold">确定</span>
                    </button>
                    <button type="button" class="btn btn-default" data-dismiss="modal"
                        style="margin-top: 20px">取消</button>
                </div>
            </div>
        </div>
    </div>

    <!--查看附件模态框-->
    <div class="modal fade" id="modal-fujianlist-select">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">查看附件清单</h4>
                </div>
                <div class="modal-body">

                    <div>
                        <table class="table table-bordered" id="bootstrap-table3" name='bootstrap-table3'></table>
                    </div>

                </div>


                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                </div>
            </div>
        </div>
    </div>

    <!--添加发票模态框-->
    <div class="modal fade" id="modal-invoice-add">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">添加发票信息</h4>
                </div>
                <div class="modal-body">
                    <form id="invoiceForm-add" class="form-horizontal" role="form">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">发票号</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="invCode" autocomplete="off">
                                <input type="hidden" name="invConId" id="invConId">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">货物名称</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="invGoodsName" autocomplete="off">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">税价合计</label>
                            <div class="col-sm-8">
                                <input type="number"
                                    onkeyup="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''"
                                    class="form-control" name="invAmount" autocomplete="off">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">开票日期</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control datepicker" name="invDate" placeholder="请选择"
                                    readonly>
                            </div>

                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">选择文件并上传</label>
                            <div class="col-sm-8">
                                <input type="hidden" class="form-control" name="" autocomplete="off">
                            </div>
                            <input id="import-file2" class="btn" type="file" name="file">
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">文件备注</label>
                            <div class="col-sm-8">
                                <textarea class="form-control text-left" rows="2" name="remark">
                        </textarea>
                            </div>
                        </div>


                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-success" id="btn-save-fapiao" data-dismiss="modal">
                        <span class="Bold">保存</span>
                    </button>
                </div>
            </div>
        </div>
    </div>

    <!--修改发票模态框-->
    <div class="modal fade" id="modal-invoice-update">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                    <h4 class="modal-title">编辑发票信息</h4>
                </div>
                <div class="modal-body">
                    <form id="invoiceForm-update" class="form-horizontal" role="form">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">发票号</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="invCode" autocomplete="off">
                                <input type="hidden" name="invId">
                                <input type="hidden" name="invConId">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">货物名称</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="invGoodsName" autocomplete="off">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">税价合计</label>
                            <div class="col-sm-8">
                                <input type="number" min="0"
                                    onkeyup="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''"
                                    class="form-control" name="invAmount" autocomplete="off">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">开票日期</label>
                            <div class="col-sm-8">
                                <input type="Date" class="form-control datepicker" name="invDate" placeholder="请选择">
                            </div>

                        </div>

                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-success" id="btn-update-fapiao" data-dismiss="modal">
                        <span class="Bold">保存</span>
                    </button>
                </div>
            </div>
        </div>
    </div>

    <section class="content-header">
        <h1 style="display:inline-block">
            项目款票编辑
        </h1>
        <button type="button" class="btn btn-success pull-right" id="btn-save3" name="btn-save3" onclick="saveData3()">
            <span class="Bold">完结</span>
        </button>
        <button type="button" class="btn btn-primary pull-right" margin-right="30px"
            onclick="javascript:window.history.back();">
            <span class="Bold">返回</span>
        </button>

    </section>
    <section class="content">
        <div class="well well-lg" style="background-color: #fff;">
            <div class="row">
                <div class="form-inline">
                    <div class="form-group">
                        <label>项目编号</label>
                        <input type="text" class="form-control" readonly
                            style="background-color: #fff; border: none; border-bottom: solid 1px #EEEEEE; min-width: 1000px !important;"
                            th:value="${info.contName}">
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="form-inline">
                    <div class="form-group">
                        <label>包含项目</label>
                        <input type="text" class="form-control" readonly
                            style="background-color: #fff; border: none; border-bottom: solid 1px #EEEEEE; min-width: 1000px !important;"
                            th:value="${info.name}">
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="form-inline">
                    <div class="form-group">
                        <label>签订日期</label>
                        <input type="text" class="form-control  text-center" readonly
                            style="background-color: #fff; border: none; border-bottom: solid 1px #EEEEEE;"
                            th:value="${#dates.format(info.contYear,'yyyy-MM-dd')}">
                    </div>

                    <div class="form-group">
                        <label>买方</label>
                        <input type="text" class="form-control  text-center" readonly
                            style="background-color: #fff; border: none; border-bottom: solid 1px #EEEEEE;"
                            th:value="${info.totalMethod}">
                    </div>

                    <div class="form-group">
                        <label>买房合同编号</label>
                        <input type="text" class="form-control  text-center" readonly
                            style="background-color: #fff; border: none; border-bottom: solid 1px #EEEEEE;"
                            th:value="${info.buyCode}">
                    </div>

                    <div class="form-group">
                        <label>卖方合同编号</label>
                        <input type="text" class="form-control  text-center" readonly
                            style="background-color: #fff; border: none; border-bottom: solid 1px #EEEEEE;"
                            th:value="${info.sellCode}">
                    </div>

                    <div class="form-group">
                        <label>类别</label>
                        <input type="text" class="form-control  text-center" readonly
                            style="background-color: #fff; border: none; border-bottom: solid 1px #EEEEEE;"
                            th:value="${info.contType}">
                    </div>

                    <div class="form-group">
                        <label>合同金额</label>
                        <input type="text" class="form-control  text-center" readonly
                            style="background-color: #fff; border: none; border-bottom: solid 1px #EEEEEE;"
                            th:value="${#numbers.formatDecimal(info.partMoney,1,2)}">
                    </div>


                    <div class="form-group" style="width: 100px;">
                        <label>数量</label>
                        <input type="text" class="form-control text-center" readonly
                            style="background-color: #fff; border: none; border-bottom: solid 1px #EEEEEE;width: 50px;"
                            th:value="${info.cnt}">
                    </div>


                    <div th:text="${info.conId}" hidden name="conId" class="conId"></div>
                    <div th:text="${info.moneyInvoiceStatue}" hidden name="moneyInvoiceStatue"></div>

                </div>
            </div>


        </div>
        <div class="row">
            <div class="col-md-6" style="padding-left:0px;">
                <div class="box  box-warning">
                    <div class="box-header">
                        <h3 class="box-title">回款信息</h3>
                    </div>
                    <!-- /.box-header -->
                    <div class="box-body no-padding">
                        <table class="table table-bordered" id="bootstrap-table1"
                            style="max-height: 300px;overflow: auto"></table>
                    </div>
                </div>

                <div class="box  box-info" id="zongbao" name="zongbao">
                    <div class="box-header">
                        <h3 class="box-title">总包方回款信息</h3>
                    </div>
                    <!-- /.box-header -->
                    <div class="box-body no-padding">
                        <table class="table table-bordered" id="bootstrap-table4"></table>
                    </div>
                </div>
            </div>

            <div class="col-md-6" style="padding-left:0px;">
                <div class="box box-success">
                    <div class="box-header">
                        <h3 class="box-title">发票信息</h3>
                        <button onclick="openCreateInvoiceModal()"
                            class="btn btn-success btn-xs pull-right">添加发票</button>
                    </div>
                    <!-- /.box-header -->
                    <div class="box-body no-padding">
                        <table class="table table-bordered" id="bootstrap-table2"></table>
                    </div>
                </div>

            </div>

        </div>


        </div>
    </section>
    <div th:include="include :: footer">
    </div>
    <script th:inline="javascript">
        var table1, table2, table3, table4;
        var flag = false;
        var timeNow = new Date();
        var mis = $("#moneyInvoiceStatue").val();
        if (mis === 1) {
            $("#btn-save3").hide();
        }

        function saveData3() {
            $.ajax({
                type: 'GET',
                url: ctx + "kpSave?conId=" + [[${ info.conId }]] + "&keditUsername=" + [[${ loginUName }]],
                processData: false,
                contentType: false,
                // dataType : 'text',
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        //切换回页面
                        location.href = ctx + "invoiceList/listIndex3";
                        js.modal.closeLoading();
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            });
        }


        $(function () {

            // 回款信息table1(非总包)
            table1 = js.table.init({
                id: "bootstrap-table1",
                url: ctx + "moneyInfoByConId?conId=" + [[${ info.conId }]],
                showColumns: false,
                showExport: false,
                pageSize: 5,
                pagination: false,
                /*onLoadSuccess: function (data) {
                    loadTable2();
                },*/
                columns: [
                    {
                        title: '序号', field: 'id', width: '50',
                        formatter: function (value, row, index, field) {
                            return index + 1;
                        }
                    },
                    {
                        title: "款项比例", field: 'rmiExpectScale',
                        formatter: function (value, row, index) {
                            return changeHundred(value, row);
                        }
                    },
                    { title: "收款项", field: 'rmiName' },
                    { title: "收款项ID", field: 'rmiMoneyType', visible: false },
                    { title: "应收金额", field: 'singleRmiExpectMoney' },
                    { title: "实际已收金额", field: 'rmiActualMoney', visible: false },
                    {
                        title: "已收金额", field: 'singleAlreadyMoney', visible: true
                        // ,formatter: function (value, row, index) {
                        //     return updateAlreadyMoney(value, row);
                        // }
                    },
                    {
                        title: "收款比例", field: 'singleCollectionScale',
                        formatter: function (value, row, index) {
                            return changeHundred(value, row);
                        }
                    },
                    { title: "抹账金额", field: 'singleRmiDebtsMoney' },
                    { title: "坏账金额", field: 'singleRmiBadMoney' },
                    {
                        title: "预计回<br>款时间", field: 'rmiExpectDate', visible: true,
                        formatter: function (value, row, index) {
                            return changeDateFormat(value)
                        }
                    },
                    {
                        title: "应收未收", field: 'singleReceivableNotReceivedMoney',
                        formatter: function (value, row, index) {
                            return timeCompare(value, row);
                        }
                    },
                    { title: "是否为总包", field: 'rmiIsAll', visible: false },
                    {
                        title: "操作", formatter: function (value, row, index) {
                            var actions = [];
                            actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="openSelectMoneyModal(' + js.jsonStringify(row) + ')"> 查看</a> ');
                            if (hasP("pay:infor:edit")) {
                                actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="openEditMoneyModal(' + js.jsonStringify(row) + ')"  > 编辑</a> ');
                            }
                            return actions.join('');
                        }
                    }
                ]
            });


            table2 = js.table.init({
                id: "bootstrap-table2",
                url: ctx + "invInfoByConId?conId=" + [[${ info.conId }]],
                showColumns: false,
                showExport: false,
                pageSize: 5,
                pagination: false,
                columns: [
                    {
                        title: '序号', field: 'id', width: '50',
                        formatter: function (value, row, index, field) {
                            return index + 1;
                        }
                    },
                    { title: "发票表主键", field: 'invId', visible: false },
                    { title: "合同表表主键", field: 'conId', visible: false },
                    { title: "发票号", field: 'invCode' },
                    { title: "货物名称", field: 'invGoodsName' },
                    {
                        title: "价税合计", field: 'invAmount',
                        formatter: function (value, row, index) {
                            return saveTwoNumber(value);
                        }
                    },
                    {
                        title: "开票日期", field: 'invDate',
                        formatter: function (value, row, index) {
                            return changeDateFormat(value)
                        }
                    },
                    { title: "记录人", field: 'invTakePerson' },
                    {
                        title: "记录时间", field: 'invCreateDate',
                        formatter: function (value, row, index) {
                            return changeDateFormat(value)
                        }
                    },
                    {
                        title: "操作", width: "120px",
                        formatter: function (value, row, index) {
                            var actions = [];
                            if (hasP("pay:infor:upload")) {
                                actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0);" onclick="uploading(' + js.jsonStringify(row) + ')"  > 上传</a> ');
                            }
                            actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0);" onclick="selectFapiaoList(' + js.jsonStringify(row) + ')" > 查看</a> ');
                            if (hasP("pay:infor:del")) {
                                actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0);" onclick="delete333(' + js.jsonStringify(row) + ')" > 删除</a> ');
                            }
                            if (hasP("pay:infor:edit")) {
                                actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0);" onclick="openUpdateInvoiceModal(' + js.jsonStringify(row) + ')" > 编辑</a> ');
                            }
                            return actions.join('');
                        }
                    }
                ]
            });


            if ([[${ info.contType }]] != "合作制造") {
                flag = true;
                $("#zongbao").hide();
            }
            table4 = js.table.init({
                id: "bootstrap-table4",
                url: ctx + "ZBmoneyInfoByConId?conId=" + [[${ info.conId }]],
                showColumns: false,
                showExport: false,
                pageSize: 300,
                pagination: false,
                columns: [
                    {
                        title: '序号', field: 'id', width: '50',
                        formatter: function (value, row, index, field) {
                            return index + 1;
                        }
                    },
                    {
                        title: "款项比例", field: 'rmiExpectScale',
                        formatter: function (value, row, index) {
                            return changeHundred(value, row);
                        }
                    },
                    { title: "收款项", field: 'rmiName' },
                    { title: "应收金额", field: 'singleRmiExpectMoney' },
                    {
                        title: "实际已收金额", field: 'rmiActualMoney', visible: true
                    },
                    {
                        title: "收款比例", field: 'singleCollectionScale',
                        formatter: function (value, row, index) {
                            return changeHundred(value, row);
                        }
                    },
                    {
                        title: "预计回<br>款时间", field: 'rmiExpectDate', visible: true,
                        formatter: function (value, row, index) {
                            return changeDateFormat(value)
                        }
                    },
                    { title: "是否为总包", field: 'rmiIsAll', visible: false },
                    {
                        title: "操作", formatter: function (value, row, index) {
                            var actions = [];
                            actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="openSelectMoneyModal(' + js.jsonStringify(row) + ')"> 查看</a> ');
                            if (hasP("pay:infor:edit")) {
                                actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="openEditMoneyModal(' + js.jsonStringify(row) + ')"> 编辑</a> ');
                            }
                            return actions.join('');
                        }
                    }
                ]
            });


        });


        //table3
        function loadTable3(id, invCode) {
            // alert(id)
            /** 加载用户表格 */
            table3 = js.table.init({
                id: "bootstrap-table3",
                url: ctx + "annexListByInvId?invId=" + id,
                showColumns: false,
                showExport: false,
                pageSize: 300,
                pagination: false,
                columns: [
                    {
                        title: '序号', field: 'id', width: '50',
                        formatter: function (value, row, index, field) {
                            var pageSize = table2.bootstrapTable('getOptions').pageSize;
                            var pageNumber = table2.bootstrapTable('getOptions').pageNumber;
                            return pageSize * (pageNumber - 1) + index + 1;
                        }
                    },
                    {
                        title: "发票号", formatter: function (value, row, index) {
                            return invCode;
                        }, visible: false
                    },
                    { title: "文件id", field: 'fileId', visible: false },
                    { title: "文件名", field: 'fileName' },
                    { title: "文件备注", field: 'fileComment' },
                    { title: "上传日期", field: 'fileUploadDate' },
                    { title: "上传者姓名", field: 'userName' },
                    { title: "路径", field: 'fileUrl', visible: false },
                    {
                        title: "操作", formatter: function (value, row, index) {
                            var actions = [];
                            if (hasP("pay:infor:download")) {
                                actions.push('<a class="btn btn-success btn-xs" href="' + row.fileUrl + '" > 下载</a> ');
                            }
                            if (hasP("pay:infor:delete")) {
                                actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0);" onclick="delete222(' + row.fileId + ',\'' + invCode + '\')" > 删除</a> ');
                            }
                            return actions.join('');
                        }
                    }
                ]
            });
        }

        //删除附件
        function delete222(fileId, invCode) {
            js.modal.confirm("确认删除吗？", function (result) {
                if (result) {
                    callBack();
                }
                $.ajax({
                    type: 'POST',
                    url: ctx + "annexDelete",
                    data: { 'fileId': fileId, "invCode": invCode },
                    success: function (msg) {
                        if (msg === "删除成功") {
                            js.modal.success(msg);
                            $("#bootstrap-table3").bootstrapTable('refresh');
                            js.modal.closeLoading();
                        } else {
                            js.modal.warning(msg);
                        }
                    }
                });
            })
        }

        function delete333(row) {
            js.modal.confirm("确认删除吗？", function (result) {
                if (result) {
                    callBack();
                }
                $.ajax({
                    type: 'GET',
                    url: ctx + "invoiceDelete?invId=" + row.invId,
                    processData: false,
                    contentType: false,
                    // dataType : 'text',
                    success: function (msg) {
                        if (msg === "删除成功") {
                            js.modal.success(msg);
                            $("#bootstrap-table2").bootstrapTable('refresh');
                            js.modal.closeLoading();
                        } else {
                            js.modal.warning(msg);
                        }
                    }
                });
            })
        }


        /**
         * 打开 添加发票 模态框
         */
        function openCreateInvoiceModal() {

            $("#modal-invoice-add [name='invConId']").val([[${ info.conId }]])
            js.modal.open("modal-invoice-add");
        }

        /**
         * 打开 编辑发票 模态框
         */
        function openUpdateInvoiceModal(row) {
            $("#modal-invoice-update [name='invId']").val(row.invId);
            $("#modal-invoice-update [name='invConId']").val(row.conId);
            $("#modal-invoice-update").fillData(row);
            $("#modal-invoice-update [name='invDate']").val(changeDateFormat(row.invDate));

            js.modal.open("modal-invoice-update");

        }


        /**
         * 打开 查看回款 模态框
         */
        function openSelectMoneyModal(row) {
            //设置输入框中各项的值
            $("#moneyForm-select").fillData(row);

            //添加 应收未收 框的值
            var ysws = timeCompare(row.singleReceivableNotReceivedMoney, row);
            $("#moneyForm-select [name='yingshouweishou']").val(ysws);

            //调整 预计回款时间 格式
            var rmiExpectDate = changeDateFormat(row.rmiExpectDate);
            $("#moneyForm-select [name='rmiExpectDate']").val(rmiExpectDate);

            //调整款项百分比
            $("#moneyForm-select [name='rmiExpectScale']").val(changeHundred(row.rmiExpectScale));

            if (row.rmiIsAll == 1) {
                $("#yswsDiv-select").hide();
                $("#mzjeDiv-select").hide();
                $("#hzjeDiv-select").hide();
                $("#ysjeDiv-select").hide();
            } else {
                $("#yswsDiv-select").show();
                $("#mzjeDiv-select").show();
                $("#hzjeDiv-select").show();
                $("#ysjeDiv-select").show();
            }

            js.modal.open("modal-select-money");

        }

        /**
         * 打开 编辑回款 模态框
         */
        function openEditMoneyModal(row) {
            $("#moneyForm-edit").fillData(row);
            //添加 应收未收 框的值
            var ysws = timeCompare(row.singleReceivableNotReceivedMoney, row);
            $("#moneyForm-edit [name='yingshouweishou']").val(ysws);
            //调整 预计回款时间 格式
            var rmiExpectDate = changeDateFormat(row.rmiExpectDate);
            $("#moneyForm-edit [name='rmiExpectDate']").val(rmiExpectDate);

            var isAll = row.rmiIsAll;
            if (isAll === 1) {
                $("#yswsDiv-edit").hide();
                $("#mzjeDiv-edit").hide();
                $("#hzjeDiv-edit").hide();
                $("#ysjeDiv-edit").hide();
            } else if (isAll === 0) {
                $("#yswsDiv-edit").show();
                $("#mzjeDiv-edit").show();
                $("#hzjeDiv-edit").show();
                $("#ysjeDiv-edit").show();
            }
            js.modal.open("modal-edit-money");
        }

        // 新  款项修改保存 （非总包  +  总包）
        function saveUpdateMoney1() {
            $("#conId").val([[${ info.conId }]]);
            js.submit({
                url: ctx + "saveUpdateMoney",
                data: new FormData($("#moneyForm-edit")[0]),
                async: true,
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.modal.closeLoading();
                        $("#bootstrap-table1").bootstrapTable('refresh');
                        $("#bootstrap-table4").bootstrapTable('refresh');
                        $("#moneyForm-edit")[0].reset();
                    } else {
                        js.modal.warning(result.msg);
                        $("#moneyForm-edit")[0].reset();
                    }
                }
            })
            js.modal.closeLoading();
        }


        // //款项修改保存 （非总包）
        // function saveData1(row) {
        //     var yishou, mozhang, huaizhang, huikuantime, rmiMoneyType, rmiName;
        //     huikuantime = $("#moneyForm-edit [name='rmiExpectDate']").val();
        //     yishou = $("#moneyForm-edit [name='singleAlreadyMoney']").val();
        //     mozhang = $("#moneyForm-edit [name='singleRmiDebtsMoney']").val();
        //     huaizhang = $("#moneyForm-edit [name='singleRmiBadMoney']").val();
        //     rmiName = $("#moneyForm-edit [name='rmiName']").val();
        //     // 1预付款、2进度款、3发货款、4到货款、5调试款、6验收款、7质保金
        //     if (rmiName == "预付款") {
        //         rmiMoneyType = 1;
        //     } else if (rmiName == "进度款") {
        //         rmiMoneyType = 2;
        //     } else if (rmiName == "发货款") {
        //         rmiMoneyType = 3;
        //     } else if (rmiName == "到货款") {
        //         rmiMoneyType = 4;
        //     } else if (rmiName == "调试款") {
        //         rmiMoneyType = 5;
        //     } else if (rmiName == "验收款") {
        //         rmiMoneyType = 6;
        //     } else if (rmiName == "质保金") {
        //         rmiMoneyType = 7;
        //     }
        //     // alert(yishou+","+mozhang+","+huaizhang+","+huikuantime);
        //     $.ajax({
        //         type: 'GET',
        //         url: ctx + "updateRmiByConIdAndRmiMoneyType?conId=" + [[${info.conId}]] + "&rmiMoneyType=" + rmiMoneyType + "&yishou=" + yishou + "&mozhang=" + mozhang + "&huaizhang=" + huaizhang + "&huikuantime=" + huikuantime,
        //         processData: false,
        //         contentType: false,
        //         // dataType : 'text',
        //         success: function (msg) {
        //             if (msg === "修改成功") {
        //                 js.modal.success(msg);
        //                 $("#bootstrap-table1").bootstrapTable('refresh');
        //                 $("#moneyForm-edit")[0].reset();
        //             } else {
        //                 js.modal.warning(msg);
        //             }
        //             //js.modal.closeLoading();
        //         }
        //     });
        //
        // }
        //
        // //款项修改保存 （总包）
        // function saveData2(row) {
        //     var yishou, mozhang, huaizhang, huikuantime, rmiMoneyType, rmiName, rmiIsAll;
        //     huikuantime = $("#moneyForm-edit [name='rmiExpectDate']").val();
        //     yishou = $("#moneyForm-edit [name='singleAlreadyMoney']").val();
        //     mozhang = $("#moneyForm-edit [name='singleRmiDebtsMoney']").val();
        //     huaizhang = $("#moneyForm-edit [name='singleRmiBadMoney']").val();
        //     rmiName = $("#moneyForm-edit [name='rmiName']").val();
        //     rmiIsAll = $("#moneyForm-edit [name='rmiIsAll']").val();
        //     // 1预付款、2进度款、3发货款、4到货款、5调试款、6验收款、7质保金
        //     if (rmiName == "预付款") {
        //         rmiMoneyType = 1;
        //     } else if (rmiName == "进度款") {
        //         rmiMoneyType = 2;
        //     } else if (rmiName == "发货款") {
        //         rmiMoneyType = 3;
        //     } else if (rmiName == "到货款") {
        //         rmiMoneyType = 4;
        //     } else if (rmiName == "调试款") {
        //         rmiMoneyType = 5;
        //     } else if (rmiName == "验收款") {
        //         rmiMoneyType = 6;
        //     } else if (rmiName == "质保金") {
        //         rmiMoneyType = 7;
        //     }
        //     // alert(yishou+","+mozhang+","+huaizhang+","+huikuantime);
        //     $.ajax({
        //         type: 'GET',
        //         url: ctx + "updateZBRmiByConIdAndRmiMoneyType?conId=" + [[${info.conId}]] + "&rmiMoneyType=" + rmiMoneyType + "&yishou=" + yishou + "&mozhang=" + mozhang + "&huaizhang=" + huaizhang + "&huikuantime=" + huikuantime,
        //         processData: false,
        //         contentType: false,
        //         success: function (msg) {
        //             if (msg === "修改成功") {
        //                 js.modal.success(msg);
        //                 $("#bootstrap-table4").bootstrapTable('refresh');
        //                 $("#moneyForm-edit")[0].reset();
        //             } else {
        //                 js.modal.warning(msg);
        //             }
        //         }
        //     });
        //
        // }


        /**
         * 比较时间  应收未收 在 预计还款日期 之前 = 0     之后 =未收
         */
        function timeCompare(value, row) {
            var d1 = new Date(Date.parse(changeDateFormat(row.rmiExpectDate)));
            if (d1 > timeNow) {
                value = "0";
            }
            if (changeDateFormat(row.rmiExpectDate) === "") {
                return "0";
            }
            return value;
        }

        /**
         * 百分比转换 保留四位小数
         * @param value
         * @returns {string}
         */
        function changeHundred(value) {
            value = String(value).replace(/^(.*\..{4}).*$/, "$1");
            value = Number(value);
            // alert(value+"-------------------------"+value* 100 + "%");
            // return value * 100 + "%";
            return (Math.round(value * 10000) / 100.00 + "%");// 小数点后两位百分比
        }


        function saveTwoNumber(value) {
            var number = value;
            return number.toFixed(2);

        }


        function changeDateFormat(value) {
            if (value === '' || value === undefined) {
                return "";
            }
            var myDate = new Date(value);
            //获取当前年
            var year = myDate.getFullYear();
            //获取当前月
            var month = myDate.getMonth() + 1;
            month = month < 10 ? "0" + month : month;
            //获取当前日
            var date = myDate.getDate();
            date = date < 10 ? "0" + date : date;
            var h = myDate.getHours();       //获取当前小时数(0-23)
            h = h < 10 ? "0" + h : h;
            var m = myDate.getMinutes();     //获取当前分钟数(0-59)
            m = m < 10 ? "0" + m : m;
            var s = myDate.getSeconds();
            s = s < 10 ? "0" + s : s;
            var time = year + '-' + month + "-" + date;
            if (time === "1900-01-01" || time === "1970-01-01") {
                return "";
            }
            return time;
        }


        /***
         * 上传附件点击
         * @param 发票id
         * */
        function uploading(row) {
            // alert(row.invId)   //发票表主键值
            var invid = row.invId
            $("#modal-import [name='invId']").val(invid);
            js.modal.open("modal-import")
        }


        /***
         * 查看附件清单
         * @param 发票id
         * */
        function selectFapiaoList(row) {
            $("#bootstrap-table3").bootstrapTable('destroy');
            // var invid = row.invId
            // alert(row.invId);
            loadTable3(row.invId, row.invCode);
            js.modal.open("modal-fujianlist-select")
        }


        /**
         * 上传附件
         */
        $("#btn-import").on('click', function () {
            js.submit({
                url: ctx + "invoice/uploadFile",
                data: new FormData($("#importForm")[0]),
                async: true,
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.modal.closeLoading();
                        js.table.search(table2);
                        $("#importForm")[0].reset();
                    } else {
                        js.modal.warning(result.msg);
                        $("#importForm")[0].reset();
                    }

                }
            })
            js.modal.closeLoading();
            js.modal.hide("modal-import");
        });

        /**
         * 添加发票
         */
        $("#btn-save-fapiao").on('click', function () {

            js.submit({
                url: ctx + "invoiceAdd",
                data: new FormData($("#invoiceForm-add")[0]),
                async: true,
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        $("#bootstrap-table2").bootstrapTable('refresh');
                        js.modal.closeLoading();
                        $("#invoiceForm-add")[0].reset();
                    } else {
                        js.modal.warning(result.msg);
                        $("#invoiceForm-add")[0].reset();
                    }
                }
            })
            js.modal.closeLoading();
            js.modal.hide("invoiceForm-add");

        });

        /**
         * 编辑发票
         */
        $("#btn-update-fapiao").on('click', function () {
            js.submit({
                url: ctx + "invoiceUpdate",
                data: new FormData($("#invoiceForm-update")[0]),
                async: true,
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        $("#bootstrap-table2").bootstrapTable('refresh');
                        js.modal.closeLoading();
                        $("#invoiceForm-update")[0].reset();
                    } else {
                        js.modal.warning(result.msg);
                        $("#invoiceForm-update")[0].reset();
                    }
                }
            })
            js.modal.closeLoading();
            js.modal.hide("invoiceForm-update");

        });


    </script>